use std::ffi::CStr;
use std::str;
pub fn atoi_idiomatic(s: &str) -> i32 {
    let mut result = 0;
    let mut sign = 1;
    let mut s = s.trim_start();
    if let Some(first_char) = s.chars().next() {
        if first_char == '+' {
            s = &s[1..];
        } else if first_char == '-' {
            sign = -1;
            s = &s[1..];
        }
    }
    for c in s.chars() {
        if let Some(digit) = c.to_digit(10) {
            if result > i32::MAX as u32 / 10 || (result == i32::MAX as u32 / 10 && digit > 7) {
                return if sign == 1 { i32::MAX } else { i32::MIN };
            }
            result = result * 10 + digit as u32;
        } else {
            break;
        }
    }
    sign * result as i32
}
fn atoi(str: *const i8) -> i32 {
    let c_str = unsafe { CStr::from_ptr(str) };
    let rust_str = c_str.to_str().unwrap_or_default();
    let result = atoi_idiomatic(rust_str);
    result
}
